/**
 * Created by gaoyj on 2018/6/28.
 */
window.onload = function (ev) {
    topbar.hide();
};
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
var date = new Date();
var currentTime = '';
date.setDate(date.getDate());
var et = new Date(date.getTime()).Format('yyyy-MM-dd');
if (currentTime && currentTime !== "undefined") {
    try {
        et = new Date(parseInt(currentTime)).Format('yyyy-MM-dd');
    } catch (e) {
        console.error(e)
    }
}
$("#startTime").val(et);
$("#dateTime").val(et);
laydate.render({
    elem: '#startTime'

});
laydate.render({
    elem: '#dateTime'
});


$('#dataTable').bootstrapTable({
    url: '/WopayMaintainController/queryNonWorkDays',
    height: $(window).height() - 200,
    pageSize: 30,
    pagination: true,
    pageList: [30, 50, 100],
    clickToSelect: true,
    singleSelect: true,
    queryParams: queryParams,
    uniqueId: 'id',
    queryParamsType: '',
    sidePagination: 'server',
    showFooter: true,
    responseHandler: function (res) {
        return {
            "total": res.length,
            "rows": res
        };
    },
    columns: [
        {
            checkbox: true
        },
        {
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        }, {align: 'center', field: 'id', visible: false},
        {
            align: 'center', field: 'time', title: '非工作日时间'
        }
    ]
});


$("#search").click(function () {
    reloadData();
});

//重载数据
function reloadData() {
    $("#dataTable").bootstrapTable("refresh");
}


$("#addTime").click(function () {
    $("#myModal1").modal("show");
});
$("#deleteTime").click(function () {
    var rows = $('#dataTable').bootstrapTable("getSelections");
    if (rows == null || rows.length === 0) {
        layer.msg("请选择要操作的订单");
        return;
    }
    $.confirm({
        title: '确认!',
        content: '确定删除维护时间吗？',
        confirm: function () {
            $.post("/WopayMaintainController/deleteNonWorkDays?id="
                + rows[0].id, function (data) {
                layer.msg(data.message);
                if (data.success) {
                    reloadData()
                    $("#myModal1").modal("hide");
                }
            });
        },
        cancel: function () {

        }
    });
});
$("#toSave").click(function () {
    if (($("#dateTime").val() == null || $("#dateTime").val() == '')) {
        layer.msg("请选择时间");
    }
    $.post("/WopayMaintainController/createNonWorkDays", $("#maintainForm").serialize(), function (data) {
        layer.msg(data.message);
        if (data.success) {
            reloadData()
            $("#myModal1").modal("hide");
        }
    })
})

function queryParams(params) {
    return {
        size: params.pageSize,
        page: params.pageNumber,
        startTime: $("#startTime").val()
    };
}
